package EXam.Question17;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 符合题目要求的实现版本
 * 使用字符缓冲流对象一次读写一行的方式来复制文本文件
 */
public class TestRequired {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                long start = System.currentTimeMillis();
                try (
                    BufferedReader br = new BufferedReader(new FileReader("a.txt"));
                    BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt"))
                ) {
                    String line;
                    // 使用字符缓冲流对象一次读写一行的方式来复制文本文件
                    while ((line = br.readLine()) != null) {
                        bw.write(line);
                        bw.newLine(); // 写入换行符
                    }
                    long end = System.currentTimeMillis();
                    System.out.println("耗时：" + (end - start) + "毫秒");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}